package com.sgb.kjwl.view.ui.adapter.home;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;

import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ItemEnterpriseRecViewBinding;
import com.swgk.core.view.entity.EnterpriseRecEntity;
import com.sgb.kjwl.view.ui.activity.manage.WebsiteInfoActivity;
import com.sgb.kjwl.view.ui.adapter.map.BaseRecycleAdapter;
import com.sgb.kjwl.view.ui.adapter.map.ItemViewHolder;

import java.util.List;

public class EnterpriseRecAdapter extends BaseRecycleAdapter<EnterpriseRecEntity> {

    public EnterpriseRecAdapter(Context context, List<EnterpriseRecEntity> data) {
        super(context, R.layout.item_enterprise_rec_view, data);
    }

    @Override
    public void convert(ItemViewHolder holder, EnterpriseRecEntity entity) {
        holder.setBinding(BR.viewModel, entity);
        ItemEnterpriseRecViewBinding binding = (ItemEnterpriseRecViewBinding) holder.getmBinding();
        if (!TextUtils.isEmpty(entity.getCompanyName())) {
            if (entity.getCompanyName().length() <= 6) {
                binding.tvContent.setText(entity.getCompanyName() + ">");
            } else {
                binding.tvContent.setText(entity.getCompanyName().substring(0, 6) + "...>");
            }
        }
        binding.getRoot().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                WebsiteInfoActivity.start(context, entity.getCompanyNo(), 1);
            }
        });
    }
}
